package com.zzedu.controller;

import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzMessage;
import com.zzedu.dto.ZzMessageDTO;
import com.zzedu.service.IZzMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 通知消息Controller
 * 
 * @author Mr.Wang
 * @date 2025-03-15
 */
@RestController
@RequestMapping("/message/message")
public class ZzMessageController extends BaseController
{
    @Autowired
    private IZzMessageService zzMessageService;

    /**
     * 查询通知消息列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('message:message:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzMessageDTO zzMessage)
    {
        return getDataTable(zzMessageService.page(zzMessage.getPageDTO(),zzMessageService.buildQuery(zzMessage)));
    }

    /**
     * 导出通知消息列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('message:message:export')")
    @Log(title = "通知消息", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzMessageDTO zzMessage)
    {
        List<ZzMessage> list = zzMessageService.list(zzMessageService.buildQuery(zzMessage));
        ExcelUtil<ZzMessage> util = new ExcelUtil<ZzMessage>(ZzMessage.class);
        util.exportExcel(ServletUtils.getResponse(),list, "通知消息数据");
    }




    /**
     * 新增保存通知消息
     */
    @PreAuthorize("@permission.hasAnyPermissions('message:message:add')")
    @Log(title = "通知消息", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@Validated @RequestBody ZzMessage zzMessage)
    {
        return toAjax(zzMessageService.save(zzMessage));
    }



    /**
     * 获取通知消息详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('message:message:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zzMessageService.getById(id));
    }


    /**
     * 修改保存通知消息
     */
    @PreAuthorize("@permission.hasAnyPermissions('message:message:edit')")
    @Log(title = "通知消息", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzMessage zzMessage)
    {
        return toAjax(zzMessageService.updateById(zzMessage));
    }

    /**
     * 删除通知消息
     */
    @PreAuthorize("@permission.hasAnyPermissions('message:message:remove')")
    @Log(title = "通知消息", businessType = BusinessType.DELETE)
	@RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(zzMessageService.removeBatchByIds(ids));
    }
}
